import net from '../../utils/net.js'
Page({
  data: {
    cardInfo:null,
    refundId:null,
    listData:[],
    page:1,
    size:10,
    count:-1,
    finish:false,
    nothing:false,
  },
  getData(id) {
    let that = this
    net.http({
      url: '/api/index/index?method=refund_plan_list',
      data: { 
        id, 
        page: that.data.page, 
        size: that.data.size 
      },
      isShowLoading: true,
      successCb: function (res) {
        if(res.data.count == 0) {
          that.setData({
            nothing:true,
            listData:[],
            finish:true
          })
        } else {
          if ((res.data.data.length + that.data.listData.length) >= res.data.count || res.data.data.length == 0) {
            that.setData({
              count:res.data.count,
              listData: [...that.data.listData, ...res.data.data],
              finish:true
            })
          } else {
            that.setData({
              count: res.data.count,
              listData: [...that.data.listData, ...res.data.data],
              finish: false
            })
          }
        }
      }
    })
  },
  onLoad: function (options) { 
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      that.setData({
        cardInfo: data.cardInfo,
        refundId: data.cardInfo.bc_id
      })
      that.getData(that.data.refundId)
    })

    // this.setData({
    //   refundId: options.id,
    // })
    
  },
  onPullDownRefresh: function () {
    this.setData({
      page:0
    })
    this.getData(this.data.refundId)
  },
  onPullDownRefresh: function () {
    if(this.data.finish) {
      return
    } else {
      this.setData({
        page: this.data.page++
      })
      this.getData(this.data.refundId)
    }
  },
})